package org.mrjbee.share.it.easy.server;

import org.restlet.data.Status;
import org.restlet.resource.ResourceException;

import com.google.appengine.api.oauth.OAuthRequestException;
import com.google.appengine.api.oauth.OAuthService;
import com.google.appengine.api.oauth.OAuthServiceFactory;

public class OAuthCheker {
	public static String getUserName(boolean throwAutorizationException){
		OAuthService oauth = OAuthServiceFactory.getOAuthService();
        try {
			return oauth.getCurrentUser().getNickname();
		} catch (OAuthRequestException e) {
			if (throwAutorizationException){
				throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN,"Please use valid token.", e);
			}
			return null;
		}
	}
}
